// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   modify_ok.java

package crm.order;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class modify_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;
	nseer_db_backup1 erp_db;

	public modify_ok()
	{
		erp_db = null;
	}

	public synchronized void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			java.io.PrintWriter out = response.getWriter();
			nseer_db_backup1 crm_db = new nseer_db_backup1(dbApplication);
			if (crm_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				counter count = new counter(dbApplication);
				String id = request.getParameter("id");
				String order_ID = request.getParameter("order_ID");
				String customer_ID = request.getParameter("customer_ID");
				String customer_name = request.getParameter("customer_name");
				String demand_customer_address = request.getParameter("demand_customer_address");
				String demand_customer_mailing_address = request.getParameter("demand_customer_mailing_address");
				String demand_contact_person = request.getParameter("demand_contact_person");
				String demand_contact_person_tel = request.getParameter("demand_contact_person_tel");
				String demand_contact_person_fax = request.getParameter("demand_contact_person_fax");
				String demand_pay_time = request.getParameter("demand_pay_time");
				String demand_pay_type = request.getParameter("demand_pay_type");
				String demand_pay_fee_type = request.getParameter("demand_pay_fee_type");
				String demand_pay_fee_sum2 = request.getParameter("demand_pay_fee_sum");
				StringTokenizer tokenTO1 = new StringTokenizer(demand_pay_fee_sum2, ",");
				String demand_pay_fee_sum;
				String demand_pay_fee_sum1;
				for (demand_pay_fee_sum = ""; tokenTO1.hasMoreTokens(); demand_pay_fee_sum = (new StringBuilder(String.valueOf(demand_pay_fee_sum))).append(demand_pay_fee_sum1).toString())
					demand_pay_fee_sum1 = tokenTO1.nextToken();

				String demand_gather_time = request.getParameter("demand_gather_time");
				String demand_gather_type = request.getParameter("demand_gather_type");
				String demand_gather_method = request.getParameter("demand_gather_method");
				String demand_invoice_type = request.getParameter("demand_invoice_type");
				String modify_time = request.getParameter("modify_time");
				String sales_name = request.getParameter("sales_name");
				String sales_ID = request.getParameter("sales_ID");
				String modifyer = request.getParameter("modifyer");
				String modifyer_ID = request.getParameter("modifyer_ID");
				String bodyc = new String(request.getParameter("invoice_info").getBytes("UTF-8"), "UTF-8");
				String invoice_info = exchange.toHtml(bodyc);
				try
				{
					String sql = (new StringBuilder("update crm_order set order_ID='")).append(order_ID).append("',customer_ID='").append(customer_ID).append("',customer_name='").append(customer_name).append("',demand_customer_address='").append(demand_customer_address).append("',demand_customer_mailing_address='").append(demand_customer_mailing_address).append("',demand_contact_person='").append(demand_contact_person).append("',demand_contact_person_tel='").append(demand_contact_person_tel).append("',demand_contact_person_fax='").append(demand_contact_person_fax).append("',demand_pay_time='").append(demand_pay_time).append("',demand_pay_type='").append(demand_pay_type).append("',demand_pay_fee_type='").append(demand_pay_fee_type).append("',demand_pay_fee_sum='").append(demand_pay_fee_sum).append("',demand_gather_time='").append(demand_gather_time).append("',demand_gather_type='").append(demand_gather_type).append("',demand_gather_method='").append(demand_gather_method).append("',demand_invoice_type='").append(demand_invoice_type).append("',modify_time='").append(modify_time).append("',sales_name='").append(sales_name).append("',sales_ID='").append(sales_ID).append("',modifyer='").append(modifyer).append("',modifyer_ID='").append(modifyer_ID).append("',invoice_info='").append(invoice_info).append("' where id='").append(id).append("'").toString();
					crm_db.executeUpdate(sql);
					String product_amount = request.getParameter("product_amount");
					int num = Integer.parseInt(product_amount);
					int pay_amount_sum = 0;
					double sale_price_sum = 0.0D;
					double cost_price_sum = 0.0D;
					for (int i = 1; i <= num; i++)
					{
						String tem_product_name = (new StringBuilder("product_name")).append(i).toString();
						String tem_product_ID = (new StringBuilder("product_ID")).append(i).toString();
						String tem_product_describe = (new StringBuilder("product_describe")).append(i).toString();
						String tem_amount = (new StringBuilder("amount")).append(i).toString();
						String tem_off_discount = (new StringBuilder("off_discount")).append(i).toString();
						String tem_list_price = (new StringBuilder("list_price")).append(i).toString();
						String tem_cost_price = (new StringBuilder("cost_price")).append(i).toString();
						String tem_amount_unit = (new StringBuilder("amount_unit")).append(i).toString();
						String product_name = request.getParameter(tem_product_name);
						String product_ID = request.getParameter(tem_product_ID);
						String product_describe = request.getParameter(tem_product_describe);
						String amount = request.getParameter(tem_amount);
						String off_discount = request.getParameter(tem_off_discount);
						String list_price2 = request.getParameter(tem_list_price);
						StringTokenizer tokenTO2 = new StringTokenizer(list_price2, ",");
						String list_price;
						String list_price1;
						for (list_price = ""; tokenTO2.hasMoreTokens(); list_price = (new StringBuilder(String.valueOf(list_price))).append(list_price1).toString())
							list_price1 = tokenTO2.nextToken();

						String cost_price2 = request.getParameter(tem_cost_price);
						StringTokenizer tokenTO3 = new StringTokenizer(cost_price2, ",");
						String cost_price;
						String cost_price1;
						for (cost_price = ""; tokenTO3.hasMoreTokens(); cost_price = (new StringBuilder(String.valueOf(cost_price))).append(cost_price1).toString())
							cost_price1 = tokenTO3.nextToken();

						String amount_unit = request.getParameter(tem_amount_unit);
						double subtotal = Double.parseDouble(list_price) * (1.0D - Double.parseDouble(off_discount) / 100D) * (double)Integer.parseInt(amount);
						double cost_price_after_discount_sum = Double.parseDouble(cost_price) * (double)Integer.parseInt(amount);
						sale_price_sum += subtotal;
						cost_price_sum += cost_price_after_discount_sum;
						pay_amount_sum += Integer.parseInt(amount);
						String sql1 = (new StringBuilder("update crm_order_details set product_ID='")).append(product_ID).append("',product_name='").append(product_name).append("',product_describe='").append(product_describe).append("',list_price='").append(list_price).append("',amount='").append(amount).append("',amount_unit='").append(amount_unit).append("',cost_price='").append(cost_price).append("',off_discount='").append(off_discount).append("',subtotal='").append(subtotal).append("' where order_ID='").append(order_ID).append("' and details_number='").append(i).append("'").toString();
						crm_db.executeUpdate(sql1);
					}

					String sql2 = (new StringBuilder("update crm_order set sale_price_sum='")).append(sale_price_sum).append("',uninvoice_sum='").append(sale_price_sum).append("',ungather_sum='").append(sale_price_sum).append("',pay_amount_sum='").append(pay_amount_sum).append("',unpay_amount_sum='").append(pay_amount_sum).append("',cost_price_sum='").append(cost_price_sum).append("' where id='").append(id).append("'").toString();
					crm_db.executeUpdate(sql2);
					response.sendRedirect("crm/order/modify_ok_a.jsp");
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
				}
				crm_db.commit();
				crm_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
